perm filename RIBMOX.SAI[NEW,AIL] blob sn#408314 filedate 1979-01-08 generic text, type T, neo UTF8
 Begin
require "std.hdr[170,161]" source!file;
! Source file: RibMox.sai;
! Rib Model for vision. Structure of model includes the following nodes
  LEFT!RIBn, RIGHT!RIBn, TOP, BOTTOM, LEFT!LUNG, RIGHT!LUNG;

! Structure of node:

     NODE
    
       NEIGHBORS
       OFFSET!PARAMS
           REL PARAMS
       INSTANCE
           LOCATION1DESCRIPTOR
               REF1COORDS
               SCALE
               REGION
               BOUNDARY
       EXCUTIVE!PROCEDURE
       THINKING!PROCEDURE
       LOOKING!PROCEDURE;

integer i,ans;
integer itemvar x,y,z,u,v,w;
require PNAMES;
require 1000 system!pdl;
item NEIGHBOR,
      UPPER!NEIGHBOR,
      LOWER!NEIGHBOR,
      RIGHT!NEIGHBOR, 
      LEFT!NEIGHBOR;
item TOP,
      BOT,
      LOCATION!DESCRIPTOR,
      XCOORD,
      YCOORD,
      XLEN,
      YLEN,
      BOUNDING!BOX,
      DELTAX,
      DELTAY,
       DELTAA;
item REFERENCE!COORDS;
item DELTA,
      INDEX,
      INSTANCE,
      LOOKING!PROCEDURE,
      LEFT,
      OFFSET!PARAMS,
      PARABOLA,
      RIB,
      RIGHT,
      SIDE,
      THINKING!PROCEDURE,
      TYPE;
itemvar array LEFT!RIB[1:10], RIGHT!RIB[1:10];
integer NumberOfRibs;
   string str;

let into = of; let of = xor; let is = eqv;

   require "PicSub.sai" source!file;

! declarations for saving LEAP triples;
require "LPDUMP[170,161]" load!module;
require "LPREAD[170,161]" load!module;
external procedure LPDUMP(string fname,device; integer words;boolean procedure filter);
simple boolean procedure DUMPAL(reference itemvar x);return(typeit(x) neq 0);
external procedure LPREAD(string fname,device; integer mode);

require "RibSub.sai" source!file;
require Verify!Datums;
require 2000 New!Items;
external procedure BAIL;
Simple Procedure InitRibArray(itemvar array RIB; string PREFIX);

  begin
  integer i;
  for i:= 1 step 1 until NumberOfRibs do
     
       begin
       RIB[i] := NEW;
       New!pname( RIB[i], PREFIX & "RIB" & CVS(i));
       Print(RIB[i]);
       Print(crlf);
       end;

   end;

Recursive Procedure MatchRib(item z);
   begin
   itemvar x,y,v;
   Print("inside marchrib, z is bound to :",z);
   if not(TYPE of z is RIB) then begin Print("MR w bad arg ",z); return; end;
   if INSTANCE of z is BIND x and
      PARABOLA of x is BIND y

            then begin
                  Print("rib ",z," already matched");
                  return;
                  end

            else begin
                 Think(z);
                 Look(z);
                 foreach v such that NEIGHBOR of z is v 
                                    and TYPE of v is RIB do
                        MatchRib(v);
                 end;
   end;


Itemvar Procedure Match(item z);
   begin
   if z = TOP then Look(TOP);

   if z = BOT then Look(BOT);

   Print("inside match z is :",z);
   if TYPE of z is RIB then MatchRib(z);

   end;

!**********************************************;
Print("Number of Ribs ="); ReadOn(NumberOfRibs);

Print("Initialize model?");ReadOn(ans);
if ans =0 then
begin


! INITIALIZE MODEL ;


InitRibArray(LEFT!RIB,"LEFT");

InitRibArray(RIGHT!RIB,"RIGHT");


! Set up neighbors;

for i := 1 step 1 until NumberOfRibs do

   begin
   if( i > 1) then
        begin
        make NEIGHBOR of LEFT!RIB[i] is LEFT!RIB[i-1];
        make UPPER!NEIGHBOR of LEFT!RIB[i] is LEFT!RIB[i-1];
        make NEIGHBOR of RIGHT!RIB[i] is RIGHT!RIB[i-1];
        make UPPER!NEIGHBOR of RIGHT!RIB[i] is RIGHT!RIB[i-1];
        end;

   
   make NEIGHBOR of LEFT!RIB[i] is RIGHT!RIB[i];
   make RIGHT!NEIGHBOR of LEFT!RIB[i] is RIGHT!RIB[i];
   make NEIGHBOR of RIGHT!RIB[i] is LEFT!RIB[i];
   make LEFT!NEIGHBOR of RIGHT!RIB[i] is LEFT!RIB[i];
   make SIDE of LEFT!RIB[i] is LEFT;
   make SIDE of RIGHT!RIB[i] is RIGHT;
   make TYPE of LEFT!RIB[i] is RIB;
   make TYPE of LEFT!RIB[i] is RIB;
   x := NEW(0);
   make INDEX of LEFT!RIB[i] is x; datum(x) := i;
   x := NEW(0);
   make INDEX of RIGHT!RIB[i] is x; datum(x) := i;


   if( i < NumberOfRibs) then
         begin
         make NEIGHBOR of LEFT!RIB[i] is LEFT!RIB[i+1];
         make LOWER!NEIGHBOR of LEFT!RIB[i] is LEFT!RIB[i+1];
         make NEIGHBOR of RIGHT!RIB[i] is RIGHT!RIB[i+1];
         make LOWER!NEIGHBOR of RIGHT!RIB[i] is RIGHT!RIB[i+1];
         end;
 

   end;
LPDUMP("Triples","DSK",1,DUMPAL);

! print out some stucture;


for i := 1 step 1 until NumberOfRibs do
   begin
   Print(RIGHT!RIB[i]);
    Print(crlf);
   foreach x such that NEIGHBOR of RIGHT!RIB[i] is x do
      Print( x );
   Print(crlf);
   end;

end
else LPREAD("Triples","DSK",2);



! add procedures;

for i :=1 step 1 until NumberOfRibs do
   begin
   MakeThinkingProcedure(RIGHT!RIB[i],ThinkRib);
   MakeThinkingProcedure(LEFT!RIB[i],ThinkRib);
   MakeLookingProcedure(RIGHT!RIB[i],LookRib);
   MakeLookingProcedure(LEFT!RIB[i],LookRib);
!   MakeOffsetParams(LEFT!RIB[i]);
!   MakeOffsetParams(RIGHT!RIB[i]);
   end;


MakeThinkingProcedure(TOP,ThinkTop);
MakeLookingProcedure(TOP,LookLungTopAndBot);
MakeThinkingProcedure(BOT,ThinkBot);
MakeLookingProcedure(BOT,LookLungTopAndBot);



!******************************************************;


  ! Print Picture;
      str := " ";
      BufInit;
      imagemode := false;
!      PrintPic;



! ***************************************************** ;
! Main control program;


Match(TOP);

Match(BOT);

Match(LEFT!RIB[5]);

!******************************************************;  

  

  end;